"""
异常的捕获
"""

# 基本捕获语法
try:
    open("/Users/dongjian/Documents/dev_file/abc.txt", "r", encoding="utf-8")
except:
    print("出现异常，因为文件不存在，我将open方法r改为w")
    open("/Users/dongjian/Documents/dev_file/abc.txt", "w", encoding="utf-8")

# 捕获指定的异常
try:
    print(name)
    # 1 / 0
except NameError as e:
    print("出现变量未定义的异常")
    print(e)

# 捕获所有的异常
print("----------------------")
try:
    print("hello")
    # 1 / 0
    # print(name)
except Exception as e:
    print("出现异常了")
else:
    print("很好，没有出现异常")
finally:
    print("我是finally，无论有没有异常，我都会执行")
